package TestPaperSystem.utils;

import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;

import java.util.List;
import java.util.stream.Collectors;

public class WordImpl {

    public static float getString(String userSet , String db){

        List<String> user = WordSegmenter.seg(userSet).stream().map(Word::getText).collect(Collectors.toList());

        List<String> dataDB = WordSegmenter.seg(db).stream().map(Word::getText).collect(Collectors.toList());

        int total = dataDB.size();

        float userAnswered = 0;

        for(String item : user)
            if(dataDB.contains(item))
                userAnswered += 1;


        return userAnswered / total;
    }
}
